
/**
 * 2023.2.27
 * maohl
 * 使用客户端播放功能，获取用户账号。
 */

var HybirdCallBackInterface = {

    TAG_WEB_quitActivity: "tag_web_quitActivity",
    TAG_WEB_appOpenOrDownload: "tag_web_appOpenOrDownload",
    TAG_WEB_openBST: "tag_web_openBST",
    TAG_OPEN_MAIN: "tag_open_main",
    isAndroid: null,
    callFunc: null,

    setCallFunction: function (_callFunc) {
        this.callFunc = _callFunc;
    },

    callByJava: function (params) {
        if (this.callFunc != null) {
            this.callFunc(JSON.parse(params));
        }
    },

    // 高清电视点确认
    openMainActivity: function () {
        if (this.isAndroidDevice()) {
            var item = {};
            item.tag = this.TAG_OPEN_MAIN;
            item.param = {};
            window.bfWebCallBack.recvWebPlay(JSON.stringify(item));
        } else {
            console.log("不是移动终端，不支持openMainActivity")
        }
    },

    //通知机顶盒发送广播，打开百视通点播内容
    sendOpenBSTBroadcast: function (contentID) {
        if (this.isAndroidDevice()) {
            var item = {};
            item.tag = this.TAG_WEB_openBST;
            item.param = {};
            item.param.contentID = contentID;
            window.bfWebCallBack.recvWebPlay(JSON.stringify(item));
        } else {
            console.log("不是移动终端，不支持跳转本地sendOpenBSTBroadcast")
        }
    },

    saveDataInLocal: function (key, value) {
        if (window.bfWebCallBack) {
            window.bfWebCallBack.saveLocalData(key, value);
            console.log("====已经保存数据,key:" + key + ", value:" + this.getDataInLocal(key));
        }
    },

    getDataInLocal: function (key) {
        if (window.bfWebCallBack) {
            console.log("====获取保存数据,key:" + key);
            return window.bfWebCallBack.getLocalData(key);
        }
        return ""
    },

    quitActivity: function (info) {

        if (this.isAndroidDevice()) {
            var item = {};
            item.tag = this.TAG_WEB_quitActivity;

            window.bfWebCallBack.recvWebPlay(JSON.stringify(item));
        } else {
            console.log("不是移动终端，quitActivity方法");
        }
    },

    appOpenOrDownload: function (downUrl, packName, appName) {
        if (this.isAndroidDevice()) {
            var item = {};
            item.tag = this.TAG_WEB_appOpenOrDownload;
            item.param = {};
            item.param.downUrl = downUrl;
            item.param.packName = packName;
            item.param.appName = appName;
            window.bfWebCallBack.recvWebPlay(JSON.stringify(item));
        } else {
            console.log("不是移动终端，appOpenOrDownload");
        }
    },

    appOpenOrDownloadWidthParam: function (downUrl, packName, appName, linkParam) {
        if (this.isAndroidDevice()) {
            var item = {};
            item.tag = this.TAG_WEB_appOpenOrDownload;
            item.param = {};
            item.param.downUrl = downUrl;
            item.param.packName = packName;
            item.param.appName = appName;
            item.param.linkParam = linkParam
            window.bfWebCallBack.recvWebPlay(JSON.stringify(item));
        } else {
            console.log("不是移动终端，appOpenOrDownload");
        }
    },

    getUserName: function () {
        if (window.bfWebCallBack) {
            return window.bfWebCallBack.getUserName();
        }
        return ""
    },

    putCacheData: function (key, value) {
        if (window.bfWebCallBack) {
            return window.bfWebCallBack.putCacheData(key, value);
        }
        return ""
    },

    getCacheData: function (key) {
        if (window.bfWebCallBack) {
            return window.bfWebCallBack.getCacheData(key);
        }
        return ""
    },
    
    //call播放器相关方法
    getTotalTime: function () {
        if (this.isAndroidDevice()) {
            return window.bsVideoCallBack.getTotalTime()
        } else {
            console.log("不是移动终端，不支持getTotalTime方法");
        }
    },

    getCurrentTime: function () {
        if (this.isAndroidDevice()) {
            return window.bsVideoCallBack.getCurrentTime()
        } else {
            console.log("不是移动终端，不支持getCurrentTime方法");
        }
    },

    seek: function (sec) {
        if (this.isAndroidDevice()) {
            window.bsVideoCallBack.seek(sec)
        } else {
            console.log("不是移动终端，不支持seek方法");
        }
    },

    pause: function () {
        if (this.isAndroidDevice()) {
            window.bsVideoCallBack.pause()
        } else {
            console.log("不是移动终端，不支持pause方法");
        }
    },

    play: function () {
        if (this.isAndroidDevice()) {
            window.bsVideoCallBack.play()
        } else {
            console.log("不是移动终端，不支持play方法");
        }
    },

    isPlaying: function () {
        if (this.isAndroidDevice()) {
            return window.bsVideoCallBack.isPlaying()
        } else {
            console.log("不是移动终端，不支持isPlaying方法");
        }
    },

    closeVideo: function () {
        if (this.isAndroidDevice()) {
            window.bsVideoCallBack.closeVideo()
        } else {
            console.log("不是移动终端，不支持closeVideo方法");
        }
    },

    playUrlVideo: function (url, left, top, width, height, isLoop) {
        if (this.isAndroidDevice()) {
            if (left === undefined) {
                window.bsVideoCallBack.playUrlVideo(url)
            } else {
                window.bsVideoCallBack.playUrlVideo(url, left, top, width, height, isLoop)
            }
        } else {
            console.log("不是移动终端，不支持playUrlVideo方法");
        }
    },

    playFullScreen: function () {
        if (this.isAndroidDevice()) {
            window.bsVideoCallBack.playFullScreen()
        } else {
            console.log("不是移动终端，不支持playFullScreen方法");
        }
    },

    isAndroidDevice: function () {
        if (this.isAndroid == null) {
            this.isAndroid = browser.versions.android;
        }

        console.log("xxxxdevice is android:" + this.isAndroid)
        return this.isAndroid;
    }

}

var browser = {
    versions: function () {
        var u = navigator.userAgent, app = navigator.appVersion;
        return {//移动终端浏览器版本信息
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
            iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
        };
    }(),

    language: (navigator.browserLanguage || navigator.language).toLowerCase()

};





